package evil.wolf.windows;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;

/**
 * A panel with the title and the text of a book.
 * 
 * @author Heidi Rakels.
 */
@SuppressWarnings("serial")
public class Book extends JPanel
{

	// Static fields.

	@SuppressWarnings("unused")
	private static final String NEWLINE = System.getProperty("line.separator");
	
	// Constructors.

	/**
	 * Constructs a book.
	 * 
	 * @param 	title		The title of the book.
	 * @param 	text		The text of the book.
	 * @param 	picture		A picture of the book.
	 */
	public Book(String title, String text, Icon picture)
	{
		
		super(new BorderLayout());
		setBackground(Color.white);
		
//        JTextPane textPane = createTextPane(title, text, picture);
//        JScrollPane paneScrollPane = new JScrollPane(textPane);
//        paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//        paneScrollPane.setPreferredSize(new Dimension(500, 350));
//        paneScrollPane.setMinimumSize(new Dimension(10, 10));
//        textPane.setCaretPosition(0);
//        this.add(paneScrollPane, BorderLayout.CENTER);
        
	}

	/**
	 * Creates the text pane for the book.
	 * 
	 * @param 	title		The title of the book.
	 * @param 	text		The text of the book.
	 * @param 	picture		A picture of the book.
	 * @return				The text pane for the book.
	 */
	
	@SuppressWarnings("unused")
	private JTextPane createTextPane(String title, String text, Icon picture) {
        JTextPane textPane = new JTextPane();
     
        return textPane;
    }
	
	
	/**
	 * Adds the styles to a styled document.
	 * 
	 * @param doc		The styled document.
	 * @param picture	A picture used in the document.
	 */
	protected void addStylesToDocument(StyledDocument doc, Icon picture) {

        Style def = StyleContext.getDefaultStyleContext().
                        getStyle(StyleContext.DEFAULT_STYLE);

        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "SansSerif");

        Style style = doc.addStyle("italic", regular);
        StyleConstants.setItalic(style, true);

        style = doc.addStyle("bold", regular);
        StyleConstants.setBold(style, true);

        style = doc.addStyle("small", regular);
        StyleConstants.setFontSize(style, 10);

        style = doc.addStyle("large", regular);
        StyleConstants.setFontSize(style, 16);
        StyleConstants.setBold(style, true);
        
        style = doc.addStyle("icon", regular);
        StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
        
        if (picture != null) {
            StyleConstants.setIcon(style, picture);
        }
    }
	
}
